package com.Interface.service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.Interface.dao.TopicInfoMapper;
import com.Interface.dao.VoteUserInfoMapper;
import com.Interface.entity.VoteUserInfo;

@Service
public class VoteUserInfoService {

	@Autowired
	VoteUserInfoMapper voteUserInfoDao;
	
	@Autowired
	TopicInfoMapper topicDao;
	
	public String userVote(Map<String, Object> param){
		String rltDesc ="";
		String vote = param.get("vote").toString();
		String[] array = vote.split(",");
		for (String str : array)
		{
			VoteUserInfo info  = new VoteUserInfo();
			info.setIsAnonymous(Integer.parseInt(param.get("is_anonymous").toString()));
			info.setOptionNo(Integer.parseInt(str));
			info.setTopicId(Integer.parseInt(param.get("topic_id").toString()));
			info.setUserId(Integer.parseInt(param.get("user_id").toString()));
			info.setVoteTime(new Date());
			voteUserInfoDao.insertSelective(info);
		}
		topicDao.updateJoinCnt(Integer.parseInt(param.get("topic_id").toString()));
		return rltDesc;
	}
	
	public  int votePersonSum(VoteUserInfo record){
		return voteUserInfoDao.votePersonSum(record);
	}
	    
	public   int votePersonDaySum(VoteUserInfo record){
		return voteUserInfoDao.votePersonDaySum(record);
	}
	    
	public    List<Map<String, Object>> voteOptionSum(VoteUserInfo record){
		return voteUserInfoDao.voteOptionSum(record);
	}
	
}
